To run this example you need to install pymongo.
pip install pymongo
In [ ]:
import pymongo
In [3]:
client = pymongo.MongoClient('localhost', 27017)
db = client['test-database']
db
Out[3]:
In [4]:
collection = db['test-collection']
collection
Out[4]:
In [5]:
collection.estimated_document_count()
Out[5]:
In [6]:
test_data = {'age': 29, 'gender': 'F', 'occupation': 'Software Engineer'}
test_data
Out[6]:
In [7]:
type(test_data)
Out[7]:
In [8]:
insert_result = collection.insert_one(test_data)
insert_result
Out[8]:
In [9]:
insert_result.acknowledged
Out[9]:
In [10]:
insert_result.inserted_id
Out[10]:
In [11]:
type(insert_result.inserted_id)
Out[11]:
In [12]:
collection.estimated_document_count()
Out[12]:
In [13]:
delete_result = collection.delete_one({'age': 29})
delete_result
Out[13]:
In [14]:
delete_result.acknowledged
Out[14]:
In [15]:
delete_result.deleted_count
Out[15]:
In [16]:
client.close()
In [ ]: